//
//  TimeMyGroup.m
//  timelyRain
//
//  Created by Jiafei Wei on 16/9/22.
//  Copyright © 2016年 Jiafei Wei. All rights reserved.
//

#import "TimeMyGroup.h"
#import "ContactGroupCell.h"
#import "TGroup.h"
@interface TimeMyGroup ()
<UITableViewDelegate,UITableViewDataSource>
{
    NSIndexPath *currentIndexPath;
    NSMutableArray *_groupC;
}
@property (weak, nonatomic) IBOutlet UITableView *table;
- (IBAction)ok:(id)sender;
- (IBAction)cancle:(id)sender;
@end

@implementation TimeMyGroup

- (void)viewDidLoad {
    [super viewDidLoad];
    currentIndexPath = [NSIndexPath indexPathForRow:0 inSection:4];
    [super setTitleView:self.view withName:@"我的分组"];
    _table.delegate =self;
    _table.dataSource =self;
    _groupC =[NSMutableArray array];
    [self initData];
}

-(void)initData{
    TGroup *g1 =[[TGroup alloc]init];
    g1.groupName =@"未分配";
    g1.selcect=YES;
    [_groupC addObject:g1];
    
    TGroup *g2 =[[TGroup alloc]init];
    g2.groupName =@"紧急联系人";
    g2.selcect=NO;
    [_groupC addObject:g2];
    
    
    TGroup *g3 =[[TGroup alloc]init];
    g3.groupName =@"家人";
    g3.selcect=NO;
    [_groupC addObject:g3];
    
    TGroup *g4 =[[TGroup alloc]init];
    g4.groupName =@"同事";
    g4.selcect=NO;
    [_groupC addObject:g4];
    
    TGroup *g5 =[[TGroup alloc]init];
    g5.groupName =@"好友";
    g5.selcect=NO;
    [_groupC addObject:g5];
    
    [_table reloadData];
}

- (IBAction)ok:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)cancle:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectio
{
    return _groupC.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ContactGroupCell *cell =[ContactGroupCell setContactGroupCellWithTableView:tableView];
    TGroup *t =[_groupC objectAtIndex:indexPath.row];
    cell.groupName =t;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (currentIndexPath!=indexPath) {
        TGroup *groupCureent =[_groupC objectAtIndex:currentIndexPath.row];
        groupCureent.selcect=NO;
        TGroup *g =[_groupC objectAtIndex:indexPath.row];
        g.selcect=YES;
        currentIndexPath =indexPath;
        [_table reloadData];//重新刷新数据
    }
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:YES];
    self.navigationController.navigationBarHidden=YES;
}


@end
